package com.apop.accompany.auth.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.apop.accompany.auth.entity.User;
import com.apop.accompany.auth.mapper.UserMapper;
import com.apop.accompany.auth.model.UserDto;
import com.apop.accompany.auth.service.lUserService;
import com.apop.common.model.PageResult;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author JiayiZheng
 * @since 2024-09-24
 */
@Service
public class UserServiceImpl  implements lUserService {

    @Resource
    UserMapper userMapper;

    @Override
    public PageResult getUserList(Integer pageNo, Integer pageSize){
        // 开启分页查询,当执行查询时，插件进行相关的sql拦截进行分页操作，返回一个page对象
        Page<User> page = PageHelper.startPage(pageNo, pageSize);
        userMapper.selectUserList(null);
        PageResult pageResult = new PageResult(page.getResult(), page.getTotal());

       return pageResult;
    }

    @Override
    public boolean updateUser(UserDto userDto) {

        User user = new User();
        BeanUtil.copyProperties(userDto,user);
        //user.setUpdateTime(LocalDateTime.now());
        return userMapper.updateUserByKey(user) > 0;
    }

}
